package com.apes.pi.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 连接器
 * 定义传输协议
 * @author wuq
 * @create 2019-10-19 10:15
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PiConnector.CONST_TABLE_NAME)
public class PiConnector extends Model {
    public static final String CONST_TABLE_NAME = "pi_connector";

    @Id
    @Column(name = "id", nullable = false, length = 32)
    @Comment("连接器编号")
    private String id;

    @Column(name = "name", nullable = false, length = 200)
    @Comment("连接器描述")
    private String name;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "protocol", referencedColumnName = "id")
    @Comment("传输协议")
    private Enumeration protocol;    // 传输协议(http、https、ws、webService等)

    @Column(name = "url", nullable = false, length = 500)
    @Comment("调用地址")
    private String url;

    @OneToMany(mappedBy = "connector", cascade=CascadeType.ALL, orphanRemoval = true)
    private List<PiConnectorParams> params;

}
